package com.smartstate.dataManagement.mapper;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.smartstate.dataManagement.entity.PowerEquipmentEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
@DS("tdengine")
public interface PowerEquipmentEntityDao extends BaseMapper<PowerEquipmentEntity> {
    boolean addPowerEquipmentEntityDao(PowerEquipmentEntity erroLogList);

    /**
     * 根据表中条件查询对应属性值
     * @param startTime
     * @param endTime
     * @param id
     * @param attribute
     * @return
     */
    @Select("select sum(${attribute}) from sh_${id} where ts >= #{startTime} and ts < #{endTime}")
    String querySum(@Param("startTime") String startTime, @Param("endTime") String endTime,
                    @Param("id") String id, @Param("attribute") String attribute);

    /**
     * 查询超级表下的所有子表
     * @param table
     * @return
     */
    @Select("select distinct(id) from ${table}")
    List<String> queryTable(@Param("table") String table);

    /**
     * 查询表是否存在
     * @param table
     * @return
     */
    @Select("show tables like sh_${table}")
    String queryTableIsEmpty(@Param("table") String table);

}
